{include file="public/layout" /}

<body class="bodystyle" style="cursor: default; -moz-user-select: inherit;min-width:auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="system/left" /}
<div class="page arctype pb15 min-hg-c-10" style="min-width:auto;margin-left:100px;">
    <div class="flexigrid">
        <div class="mDiv pt0">
            <div class="ftitle">
                {eq name="'ShopFreight@add'|is_check_access" value="1"}
                <div class="fbutton"><a href="{:url('ShopFreight/add')}"><div class="add"><span><i class="layui-icon layui-icon-addition"></i>新增运费模板</span></div></a></div>
                {/eq}
            </div>
            <form class="navbar-form form-inline" id="searchForm" action="{:url('ShopFreight/index')}" method="get" onsubmit="layer_loading('正在处理');">
                {$searchform.hidden|default=''}
                <div class="sDiv">
                    <div class="sDiv2">
                        <input type="text" size="30" name="keywords" value="{$Request.param.keywords}" class="qsbox" placeholder="搜索相关数据...">
                        <input type="submit" class="btn" value="搜索">
                        <i class="iconfont e-sousuo"></i>
                    </div>
                </div>
            </form>
        </div>

        <div class="hDiv">
            <div class="hDivBox">
                <table cellpadding="0" cellspacing="0" style="width: 100%">
                    <thead>
                        <tr>
                            <th abbr="article_title" axis="col3" class="w50">
                                <div class="tc">ID</div>
                            </th>
                            <th axis="col2" class=""> <div class="text-l10">模板名称</div> </th>
                            <th axis="col2" class="w200"> <div class="tc">快递公司</div> </th>
                            <th axis="col2" class="w100"> <div class="tc">状态</div> </th>
                            <th axis="col2" class="w80"> <div class="tc">是否默认</div> </th>
                            <th axis="col2" class="w100"> <div class="tc">操作</div> </th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>

        <div class="bDiv" style="height: auto; min-height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody id="treet1">
                    {empty name="template"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <div class="no_row">
                                    <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                </div>
                            </td>
                        </tr>
                    {else/}
                        {foreach name="template" item="vo" key="k" }
                        <tr>
                            <td class="sort">
                                <div class="tc w50">
                                    {if condition="$pager->nowPage > 1"}
                                        {$pager->listRows * ($pager->nowPage-1) + $k+1}
                                    {else /}
                                        {$k+1}
                                    {/if}
                                </div>
                            </td>
                            <td style="width: 100%;">
                                <div class="text-l10">
                                    {$vo.template_name} &nbsp; 
                                    {eq name="$vo.default" value="1"}<span class="address_default">默认</span>{/eq}
                                </div>
                            </td>
                            <td class="sort">
                                <div class="tc w200">
                                    {$vo.express_name}
                                </div>
                            </td>
                            <td class="">
                                <div class="tc w100">
                                    {if condition="$vo['status'] eq 1"}
                                        <span class="yes" {eq name="'ShopFreight@edit'|is_check_access" value="1"}onClick="changeTableVal('shop_freight_template','template_id','{$vo.template_id}','status',this);"{/eq} data-yestext='<i class="fa fa-check-circle"></i>启用' data-notext='<i class="fa fa-ban"></i>禁用'><i class="fa fa-check-circle"></i>启用</span>
                                    {else /}
                                        <span class="no" {eq name="'ShopFreight@edit'|is_check_access" value="1"}onClick="changeTableVal('shop_freight_template','template_id','{$vo.template_id}','status',this);"{/eq} data-yestext='<i class="fa fa-check-circle"></i>启用' data-notext='<i class="fa fa-ban"></i>禁用'><i class="fa fa-ban"></i>禁用</span>
                                    {/if}
                                </div>
                            </td>
                            <td class="">
                                <div class="tc w80">
                                    {if condition="$vo['default'] eq 1"}
                                        <span class="yes" {eq name="'ShopFreight@edit'|is_check_access" value="1"}onClick="changeTableVal('shop_freight_template','template_id','{$vo.template_id}','default',this);"{/eq} data-value="2" data-yestext='<i class="fa fa-check-circle"></i>' data-notext='<i class="fa fa-ban"></i>'><i class="fa fa-check-circle"></i></span>
                                    {else /}
                                        <span class="no" {eq name="'ShopFreight@edit'|is_check_access" value="1"}onClick="changeTableVal('shop_freight_template','template_id','{$vo.template_id}','default',this);"{/eq} data-value="1" data-yestext='<i class="fa fa-check-circle"></i>' data-notext='<i class="fa fa-ban"></i>'><i class="fa fa-ban"></i></span>
                                    {/if}
                                </div>
                            </td>
                            <td class="operation">
                                <div class="w100 tc">
                                    <a href="{:url('ShopFreight/edit', ['template_id'=>$vo.template_id])}" class="btn blue">编辑</a>
                                    <a href="JavaScript:void(0);" onclick="templateDel(this);" data-template_id="{$vo.template_id}" class="btn red">删除</a>
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    {/empty}
                    </tbody>
                </table>
            </div>
        </div>

        <div class="tDiv"> <div class="tDiv2"> {include file="public/page" /} </div> <div style="clear:both"></div> </div>
    </div>
</div>

{include file="public/footer" /}
<script type="text/javascript">
    $(function() {
        $(document).keydown(function(event){
            if (event.keyCode ==13) {
                $('#searchForm input[type=text]').each(function(index, item){
                    if ($(item).is(':focus')) {
                        $('#searchForm').submit();
                    }
                });
            }
        });
    });

    // 运费模板设置默认
    // function templateDefault(obj) {
    //     var title;
    //     var value = $(obj).attr('data-default');
    //     var template_id = $(obj).attr('data-template_id');
    //     if (1 === parseInt(value)) {
    //         value = 2;
    //         title = '确认取消默认模板？';
    //     } else if (2 === parseInt(value)) {
    //         value = 1;
    //         title = '确认设置默认模板？';
    //     }
    //     layer.alert(title, {
    //         move: false,
    //         closeBtn: 3,
    //         btnAlign:'r',
    //         title: '提示',
    //         shade: layer_shade,
    //         btn: ['确认', '关闭'],
    //         area: ['480px', '190px'],
    //         success: function () {
    //             $(".layui-layer-content").css('text-align', 'left');
    //         }
    //     }, function() {
    //         layer_loading('正在处理');
    //         $.ajax({
    //             type: 'post',
    //             url : "{:url('ShopFreight/ajaxTemplateDefault')}",
    //             data: {template_id: template_id, value: value, _ajax: 1},
    //             dataType: 'json',
    //             success: function(res) {
    //                 layer.closeAll();
    //                 if (1 === parseInt(res.code)) {
    //                     layer.msg(res.msg, {icon: 1, time: 1000}, function() {
    //                         window.location.reload();
    //                     });
    //                 } else {
    //                     // 提示内容
    //                     showErrorMsg(res.msg);
    //                 }
    //             }
    //         });
    //     });
    // }

    // 运费模板状态设置
    // function templateStatus(obj) {
    //     var title;
    //     var value = $(obj).attr('data-status');
    //     var template_id = $(obj).attr('data-template_id');
    //     if (1 === parseInt(value)) {
    //         value = 2;
    //         title = '确认禁用运费模板？';
    //     } else if (2 === parseInt(value)) {
    //         value = 1;
    //         title = '确认启用运费模板？';
    //     }
    //     layer.alert(title, {
    //         move: false,
    //         closeBtn: 3,
    //         btnAlign:'r',
    //         title: '提示',
    //         shade: layer_shade,
    //         btn: ['确认', '关闭'],
    //         area: ['480px', '190px'],
    //         success: function () {
    //             $(".layui-layer-content").css('text-align', 'left');
    //         }
    //     }, function() {
    //         layer_loading('正在处理');
    //         $.ajax({
    //             type: 'post',
    //             url : "{:url('ShopFreight/ajaxTemplateStatus')}",
    //             data: {template_id: template_id, value: value, _ajax: 1},
    //             dataType: 'json',
    //             success: function(res) {
    //                 layer.closeAll();
    //                 if (1 === parseInt(res.code)) {
    //                     layer.msg(res.msg, {icon: 1, time: 1000}, function() {
    //                         window.location.reload();
    //                     });
    //                 } else {
    //                     // 提示内容
    //                     showErrorMsg(res.msg);
    //                 }
    //             }
    //         });
    //     });
    // }

    // 运费模板删除
    function templateDel(obj) {
        var template_id = $(obj).attr('data-template_id');
        layer.alert('确认删除运费模板？', {
            move: false,
            closeBtn: 3,
            btnAlign:'r',
            title: '提示',
            shade: layer_shade,
            btn: ['确认', '关闭'],
            area: ['480px', '190px'],
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            layer_loading('正在处理');
            $.ajax({
                type: 'post',
                url : "{:url('ShopFreight/ajaxTemplateDel')}",
                data: {template_id: template_id, _ajax: 1},
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 === parseInt(res.code)) {
                        layer.msg(res.msg, {icon: 1, time: 1000}, function() {
                            window.location.reload();
                        });
                    } else {
                        // 提示内容
                        showErrorMsg(res.msg);
                    }
                }
            });
        });
    }
</script>